/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Raytracing.BRDF;

import Raytracing.Constants;
import Raytracing.Ray;
import Raytracing.Sampling;
import Raytracing.Shaders.TextureProvider;
import SGGUI.GUIEvent;
import SGGUI.GUIListener;
import processing.core.PVector;

/**
 *
 * @author Matt
 */
public class LambertBRDF implements BRDF, GUIListener{

    TextureProvider R;


    
    public LambertBRDF(TextureProvider R) {
        this.R = R;

    }

    public PVector getReflectance(PVector incoming, PVector outgoing, PVector normal, float tu, float tv, PVector u, PVector v) {

        PVector ret = new PVector();
        R.getColor(tu, tv, ret);
        ret.div(Constants.PI);

        return ret;
    }

    public float sampleReflectance(PVector outgoing, Ray sample,
            PVector normal, PVector BRDF,
            float tu, float tv, PVector u, PVector v,
            float u1, float u2) {


        Sampling.cosineSampleHemisphere(sample.direction, u1, u2);

        BRDF.set(getReflectance(outgoing, sample.direction, normal, tu, tv, u, v));

        sample.bounceType = Ray.DIFFUSE;

        return 1.f / Constants.PI;
    }

    public void GUIEventPerformed(GUIEvent e) {
        
    }
}
